namespace Example
{
    using System.Net;
    using Example.Properties;
    using SimpleWebServices.Net;
    using SimpleWebServices.Web;
    using Xunit;

    public sealed class GreetingFacts
    {
        private static readonly Resource _english = new GenericResource().ApplyDefaultValues<GenericResource>();
        private static readonly Resource _french = new GenericResource().ApplyDefaultValues<GenericResource>();

        [Fact]
        public void Get_LanguageNegotiation()
        {
            Assert.True(HttpExpectations.New("http://example.simplewebservices.org/greeting")
                .AcceptAnyContent()
                .AcceptAnyLanguage()
                .Cookieless()
                .Get()
                .IsLanguageNegotiationToEnglish()
                .HasNoCookies()
                .Result);
        }

        [Fact]
        public void Get_en_ContentNegotiation_html()
        {
            Assert.True(HttpExpectations.New("http://example.simplewebservices.org/greeting.en")
                .AcceptAnyContent()
                .AcceptAnyLanguage()
                .Cookieless()
                .Get()
                .IsContentNegotiationToTextHtml()
                .HasNoCookies()
                .Result);
        }

        [Fact]
        public void Get_en_ContentNegotiation_xhtml()
        {
            Assert.True(HttpExpectations.New("http://example.simplewebservices.org/greeting.en")
                .Accept("application/xhtml+xml")
                .AcceptAnyLanguage()
                .Cookieless()
                .Get()
                .IsSeeOther("http://example.simplewebservices.org/greeting.en.xhtml")
                .HasNoCookies()
                .Result);
        }

        [Fact]
        public void Get_en_HtmlRepresentation()
        {
            Assert.True(HttpExpectations.New("http://example.simplewebservices.org/greeting.en.html")
                .AcceptAnyContent()
                .AcceptAnyLanguage()
                .Cookieless()
                .Get()
                .Is(HttpStatusCode.OK)
                .HasCacheControlPublic()
                .WithExpires()
                .IgnoreContentLanguage()
                .HasContentMD5()
                .ResponseIsTextHtml(_english)
                .HasStyleSheetLink(Settings.Default.Stylesheet)
                .HasRobotsTag("FOLLOW,INDEX")
                .Evaluate<double>(1, Analytics.Xpath)
                .Evaluate<double>(1, "count(//p[@id='value'])")
                .HasNoCookies()
                .Result);
        }

        [Fact]
        public void Get_en_XhtmlRepresentation()
        {
            Assert.True(HttpExpectations.New("http://example.simplewebservices.org/greeting.en.xhtml")
                .AcceptAnyContent()
                .AcceptAnyLanguage()
                .Cookieless()
                .Get()
                .Is(HttpStatusCode.OK)
                .HasCacheControlPublic()
                .WithExpires()
                .IgnoreContentLanguage()
                .HasContentMD5()
                .ResponseIsApplicationXhtml(_english)
                .HasStyleSheetLink(Settings.Default.Stylesheet)
                .HasRobotsTag("FOLLOW,INDEX")
                .Evaluate<double>(1, Analytics.Xpath)
                .Evaluate<double>(1, "count(//p[@id='value'])")
                .HasNoCookies()
                .Result);
        }

        [Fact]
        public void Get_fr_HtmlRepresentation()
        {
            Assert.True(HttpExpectations.New("http://example.simplewebservices.org/greeting.fr.html")
                .AcceptAnyContent()
                .AcceptAnyLanguage()
                .Cookieless()
                .Get()
                .Is(HttpStatusCode.OK)
                .HasCacheControlPublic()
                .WithExpires()
                .IgnoreContentLanguage()
                .HasContentMD5()
                .ResponseIsTextHtml(_french)
                .HasStyleSheetLink(Settings.Default.Stylesheet)
                .HasRobotsTag("FOLLOW,INDEX")
                .Evaluate<double>(1, Analytics.Xpath)
                .Evaluate<double>(1, "count(//p[@id='value'])")
                .HasNoCookies()
                .Result);
        }

        [Fact]
        public void Get_fr_XhtmlRepresentation()
        {
            Assert.True(HttpExpectations.New("http://example.simplewebservices.org/greeting.fr.xhtml")
                .AcceptAnyContent()
                .AcceptAnyLanguage()
                .Cookieless()
                .Get()
                .Is(HttpStatusCode.OK)
                .HasCacheControlPublic()
                .WithExpires()
                .IgnoreContentLanguage()
                .HasContentMD5()
                .ResponseIsApplicationXhtml(_french)
                .HasStyleSheetLink(Settings.Default.Stylesheet)
                .HasRobotsTag("FOLLOW,INDEX")
                .Evaluate<double>(1, Analytics.Xpath)
                .Evaluate<double>(1, "count(//p[@id='value'])")
                .HasNoCookies()
                .Result);
        }
    }
}